<template>
  <div class="app-container">
    <!-- <div>
      <el-form :model="listQuery" :inline="true" style="margin-left: 20px">
        <el-form-item label="用户操作:" label-width="80px" size="medium">
          <el-input v-model="listQuery.operation" type="text" />
        </el-form-item>
        <el-form-item label="用户:" label-width="50px" size="medium" style="margin-left: 20px">
          <el-input v-model="listQuery.uid" type="text" />
        </el-form-item>
        <el-form-item label="时间范围:" label-width="80px" size="medium" style="margin-left: 20px">
          <el-date-picker
            v-model="listQuery.dateRange"
            size="medium"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="--"
            start-placeholde="开始日期"
            end-placeholde="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="medium"
            style="margin-left: 30px; height: 35px"
            @click="fetchData"
          >筛选</el-button>
        </el-form-item>
      </el-form>
    </div> -->

    <div>
      <el-table
        :data="list"
      >
        <el-table-column label="日志编号" min-width="30%" align="center">
          <template slot-scope="scope">
            {{ scope.row.logid }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="用户名" min-width="40%" align="center">
          <template slot-scope="scope">
            {{ scope.row.uid }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="用户操作" min-width="70%" align="center">
          <template slot-scope="scope">
            {{ scope.row.operation }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="操作类型" min-width="40%" align="center">
          <template slot-scope="scope">
            {{ scope.row.type }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" min-width="80%" align="center">
          <template slot-scope="scope">
            {{ scope.row.time }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="请求方法" min-width="120%" align="center">
          <template slot-scope="scope">
            {{ scope.row.method }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="请求参数" min-width="120%" align="center">
          <template slot-scope="scope">
            {{ scope.row.params }}
          </template>
        </el-table-column>
        <el-table-column label="请求地址" min-width="50%" align="center">
          <template slot-scope="scope">
            {{ scope.row.ip }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="fetchData" />

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getOperlog } from '@/api/operlog'

export default {
  name: 'Operlog',
  components: { Pagination },
  data() {
    return {
      list: null,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        uid: '',
        operation: ''
        // dateRange: []
      },
      total: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      getOperlog(this.listQuery).then(res => {
        if (res.code === 200) {
          this.list = res.data.list
          this.total = res.data.total
        } else {
          this.$message.error(res.msg || '分页获取操作日志失败')
        }
      }).catch(() => {
        this.$message.error('分页获取操作日志失败')
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
